package com.chw.admin.lookup;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chw.annotation.PermissionSecurity;
import com.chw.common.ServiceData;
import com.chw.utils.LogUtil;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;

@Controller
@RequestMapping({ "/lookup" })
public class SysLookupValueController {
	private static LogUtil log = LogUtil.newInstance(SysLookupValueController.class);

	@Autowired
	private ISysLookupValueService sysLookupValueService;

	// @RequestMapping(value = { "/find.do" }, method = {
	// org.springframework.web.bind.annotation.RequestMethod.POST }, consumes =
	// {
	// "*/*" }, produces = { "application/json" })
	// @ResponseBody
	// @PermissionSecurity(name = "查询", module = "快速编码", btnfunc = "find")
	// public ServiceData find(HttpServletRequest request, SysLookupValue
	// sysLookupValue, Integer currentPage,
	// Integer pageSize) throws Exception {
	// ServiceData ret = new ServiceData();
	// PageInfo<SysLookupValue> chw =
	// this.sysLookupValueService.findEntity(sysLookupValue, currentPage,
	// pageSize);
	// ret.setCode(request, ServiceData.RetCode.Success);
	// ret.setBo(chw);
	// return ret;
	// }

	@RequestMapping(value = { "/find.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "查询", module = "快速编码", btnfunc = "find")
	public ServiceData find(HttpServletRequest request, SysLookupType sysLookupType, Integer currentPage,
			Integer pageSize) throws Exception {
		ServiceData ret = new ServiceData();
		PageInfo<SysLookupType> chw = this.sysLookupValueService.findEntity(sysLookupType, currentPage, pageSize);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	@RequestMapping(value = { "/findLookupValue.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "查询", module = "快速编码", btnfunc = "findLookupValue")
	public ServiceData findLookupValue(HttpServletRequest request, SysLookupValue sysLookupValue, Integer currentPage,
			Integer pageSize) throws Exception {
		ServiceData ret = new ServiceData();
		PageInfo<SysLookupValue> chw = this.sysLookupValueService.findEntity(sysLookupValue, currentPage, pageSize);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	@RequestMapping(value = { "/getEntityById.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "根据id查询", module = "快速编码", btnfunc = "getEntityById")
	public ServiceData getEntityById(HttpServletRequest request, String id) throws Exception {
		ServiceData ret = new ServiceData();
		SysLookup chw = this.sysLookupValueService.getEntityById(id);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	@RequestMapping(value = { "/save.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "新增", module = "快速编码", btnfunc = "save")
	public ServiceData save(HttpServletRequest request, String param) throws Exception {
		ServiceData ret = new ServiceData();
		Gson gson = new Gson();
		// SysLookupValue sysLookupValue = (SysLookupValue) gson.fromJson(param,
		// SysLookupValue.class);
		// int i = this.sysLookupValueService.addEntity(sysLookupValue);
		SysLookup sysLookup = (SysLookup) gson.fromJson(param, SysLookup.class);
		int i = this.sysLookupValueService.addEntity(sysLookup.getSysLookupType(), sysLookup.getSysLookupValue());
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}

	@RequestMapping(value = { "/update.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "修改", module = "快速编码", btnfunc = "update")
	public ServiceData update(HttpServletRequest request, String param) throws Exception {
		ServiceData ret = new ServiceData();
		Gson gson = new Gson();
		// SysLookupValue sysLookupValue = (SysLookupValue) gson.fromJson(param,
		// SysLookupValue.class);
		// int i = this.sysLookupValueService.updateEntity(sysLookupValue);
		SysLookup sysLookup = (SysLookup) gson.fromJson(param, SysLookup.class);
		int i = this.sysLookupValueService.updateEntity(sysLookup.getSysLookupType(), sysLookup.getSysLookupValue());
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}

	@RequestMapping(value = { "/delete.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "删除", module = "快速编码", btnfunc = "delete")
	public ServiceData delete(HttpServletRequest request, String lookupType) throws Exception {
		ServiceData ret = new ServiceData();
		int i = this.sysLookupValueService.deleteEntity(lookupType);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}
}